﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace StudentDatabase
{
    public partial class xskcContext : DbContext
    {
        public xskcContext()
        {
        }

        public xskcContext(DbContextOptions<xskcContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Student> Students { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseMySql("server=127.0.0.1;user id=root;password=root;port=9999;database=xskc;SslMode=None", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.5.27-mysql"));
            }
            
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasCharSet("utf8mb4")
                .UseCollation("utf8mb4_unicode_ci");

            modelBuilder.Entity<Student>(entity =>
            {
                entity.HasKey(e => e.Sno)
                    .HasName("PRIMARY");

                entity.ToTable("student");

                entity.HasIndex(e => e.Sid, "sid")
                    .IsUnique();

                entity.Property(e => e.Sno)
                    .HasMaxLength(9)
                    .HasColumnName("sno");

                entity.Property(e => e.Sid)
                    .HasColumnType("int(6)")
                    .ValueGeneratedOnAdd()
                    .HasColumnName("sid");

                entity.Property(e => e.Sname)
                    .IsRequired()
                    .HasMaxLength(8)
                    .HasColumnName("sname");

                entity.Property(e => e.Ssex)
                    .IsRequired()
                    .HasMaxLength(2)
                    .HasColumnName("ssex");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
